


const Message = (function () {
    // 
    Message.prototype.status = "say status";
    function Message() {
        this.instance = null;
        this.status = "nihao";
    }
    Message.getInstance = function () {
        if (!this.instance) {
            this.instance = new Message();
        }
        return this.instance;
    }

    /**
    * @description: 启动WhatsApp
    * @return {*}
    */
    Message.prototype.launch = function () {
        $app.launch("com.whatsapp.w4b");
        sleepEx(2000);
        let time1 = new Date().getTime();
        while (!findWidget({ text: "Chats", id: "com.whatsapp.w4b:id/tab", className: "android.widget.TextView" }, "tic")) {
            clickWidget(findWidget({ text: "OK", id: "android:id/button2", className: "android.widget.Button" }, "tic"));
            clickWidget(findWidget({ id: "com.whatsapp.w4b:id/cancel", className: "android.widget.ImageButton" }, "ic"));

            let time2 = new Date().getTime();
            let time3 = parseInt(time2 - time1) / 1000;
            if (time3 > 15) {
                $app.launch("com.whatsapp.w4b");
                sleepEx(2000);
                time1 = new Date().getTime();
            }
            sleep(500);
        }
        this.status = "registerProcess";

    }

    Message.prototype.say = function () {
        console.log("say hi");
    }

    /**
     * @description: 是否已经修改了vpn
     * @param {String} country 国家名-中文
     * @return {Boolean} Boolean true:已修改，不需要修改，false：未修改，需要修改。
     */
    Message.prototype.isChangeVpn = function (country) {
        try {
            let res = http.get("http://cip.cc");
            if (res.statusCode == 200) {
                let retData = res.body.string();
                // console.log(retData);
                let startPoint = retData.indexOf("数据二	:");
                let endPoint = retData.indexOf("数据三");
                let str01 = retData.slice(startPoint + "数据二	:".length, endPoint);
                let ipCountry = str01.trim();
                console.log(ipCountry);
                return ipCountry.indexOf(country) > -1 ? true : false;
            }

        } catch (error) {
            console.log("判断ip国家报错: ", error);
        }

        return false;
    }
    Message.prototype.test002 = function () {
        this.status = "test002";

    }

    Message.prototype.main = function () {
        console.log(Message.prototype.status);
        let result = Message.prototype.isChangeVpn("美国");
        console.log(result);
    }
    return Message;
})().getInstance();


// Message.test002();
// console.log(Message.status);
// Message.status = "test003";
// console.log(Message.status);

// back();



